<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */

/**
 * Form for filtering what statistics to be shown on the
 * statistics page showing work hours
 *
 * @category    RedCross
 * @package     Admin_Form_Shift
 */
class Admin_Form_Statistics_DateFilter extends RedCross_Form
{
	
	public function init()
	{
        $this->setAttrib('id', 'date_filter');

        $this->addElement('text', 'from_date', array(
			'validators'	=> array(
				array('Date', true, array('locale' => 'nb_NO')),
                array('ValidDate', true, array('type' => 'from_date', 'earlier' => true))
			),
            'required'      => false,
            'label'         => 'Starttidspunkt (f.o.m.)',
		));
        
		$this->addElement('text', 'to_date', array(
            'validators'	=> array(
				array('Date', true, array('locale' => 'nb_NO')),
                array('ValidDate', true, array('type' => 'to_date', 'earlier' => true))
			),
			'required'      => false,
			'label'         => 'Slutttidspunkt (t.o.m.)'
		));
	}
	
	protected function addSubmitButton()
	{
		$this->addElement('submit', 'filter', array(
			'label' 	=> 'Søk',	
			'required' 	=> false,
			'ignore'	=> true
		));

        $this->getElement('filter')->setDecorators($this->_buttonElementDecorators);
	}
	
	public function fillForm($values)
	{
		if (array_key_exists('from_date', $values)) {
			$this->getElement('from_date')->setValue($values['from_date']);
		} else {
			$this->getElement('from_date')->setValue(date("d.m.Y", strtotime("-1 year")));
		}
		if (array_key_exists('to_date', $values)) {
			$this->getElement('to_date')->setValue($values['to_date']);
		} else {
			$this->getElement('to_date')->setValue(date("d.m.Y"));
		}
	}	
}